package com.zy.pool.pool;

import com.zy.pool.domain.DBbean;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;

/**
 * @author Angle
 * @package: com.zy.pool.pool
 * @describe: TODO
 * @date: 2018/02/06
 **/
public class DBInfoImpl extends AbstractDBInitInfo {
    Properties properties=new Properties();

    String[] attributeNames={"dataSource.driverClassName","dataSource.url","dataSource.username","dataSource.password"};
    private void attributeSet(){
        InputStream resourceAsStream = this.getClass().getResourceAsStream("jdbc.properties");
        try {
            properties.load(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Override
   public  DBbean loadProperty() {
        DBbean dBbean=new DBbean();
        attributeSet();
        Set<String> names = properties.stringPropertyNames();
        if(!names.isEmpty()){
            dBbean.setDriverName(properties.getProperty(attributeNames[0]));
            dBbean.setUrl(properties.getProperty(attributeNames[1]));
            dBbean.setUserName(properties.getProperty(attributeNames[2]));
            dBbean.setPassword(properties.getProperty(attributeNames[3]));
        }
        return dBbean;
    }
}
